package com.gitee.wsl.mathematics.coordinate.ext


import com.gitee.wsl.mathematics.vector.ext.cross
import com.gitee.wsl.mathematics.vector.ext.dot
import com.gitee.wsl.mathematics.vector.vec3.Vec3
import com.gitee.wsl.mathematics.vector.vec3.Vec3f


/**
 * Returns a unit vector orthogonal to this vector.
 */
val Vec3f.ortho:Vec3f get() {
    val ax = when {
        this.dot(Vec3f.X_AXIS) < 0.5 -> Vec3f.X_AXIS
        this.dot(Vec3f.Y_AXIS) < 0.5 -> Vec3f.Y_AXIS
        else -> Vec3f.Z_AXIS
    }
    return ax.cross(this).normalized
}

val Vec3.ortho:Vec3 get() {
    val ax = when {
        this.dot(Vec3.X_AXIS) < 0.5 -> Vec3.X_AXIS
        this.dot(Vec3.Y_AXIS) < 0.5 -> Vec3.Y_AXIS
        else -> Vec3.Z_AXIS
    }
    return ax.cross(this).normalized
}